package com.daisyday.demo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils01 {
    public final static SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");



    public static void main(String[] args) throws ParseException {
        Date parse = dft.parse("2021-07-04 00:00:01");


        Calendar calendar = Calendar.getInstance();
        calendar.setTime(parse);


        for (int i=0;i<1000;i++){
            Date time = calendar.getTime();
            System.out.println(dft.format(time));
            System.out.println(dft.format(lastWeekDay(time)));
            calendar.add(Calendar.DATE,1);
            System.out.println("-------------");
        }

    }

    public static Date lastWeekDay(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //找到本周周一的日期
        while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            calendar.add(Calendar.DAY_OF_WEEK, -1);
        }
        calendar.add(Calendar.DATE,-3);
        return calendar.getTime();
    }



}
